package com.wnxy.portal.common.exception;

import com.wnxy.portal.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常
 */
@RestControllerAdvice
public class GlobalException {

    /**
     * @ExceptionHandler指定处理BusinessException类型的异常
     */
    @ExceptionHandler(BusinessException.class)
    public Result handlerBusinessException(BusinessException e) {
        e.printStackTrace();
        return Result.fail(e.getResultCode());
    }

    /**
     * 当异常没有匹配到具体的类型时候，执行当前方法
     */
    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception e) {
        e.printStackTrace();
        return Result.fail(e.getMessage());
    }
}
